package guoanmaker.operator.business.dao;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import guoanmaker.operator.business.model.OperatorCoupons;
import guoanmaker.operator.business.model.OperatorRefuseRecord;
import guoanmaker.operator.business.model.OperatorSecckill;
import guoanmaker.operator.business.model.ProvideCommodity;
import guoanmaker.operator.business.modelnobind.BusinessServiceRange;
import guoanmaker.operator.business.modelnobind.OderFormRo;
import guoanmaker.operator.business.modelnobind.Orderforbusiness;
import guoanmaker.operator.business.modelnobind.ProvideOrderFormForOrder;
import guoanmaker.operator.business.repository.OperatorCouponsRepository;
import guoanmaker.operator.business.repository.OperatorRefuseRecordRepository;
import guoanmaker.operator.business.repository.OperatorSecckillRepository;
import guoanmaker.operator.business.repository.PersonalUserCouponRepository;
import guoanmaker.operator.business.repository.ProvideOrderFormRepository;

@Repository
public class OperatorProviderOrderDao {
	@PersistenceContext
	EntityManager em;
	
	@Autowired
	private OperatorCouponsRepository  operatorCouponsRepository;
	
	@Autowired
	private  PersonalUserCouponRepository  personalUserCouponRepository;
	
	@Autowired
	private  OperatorSecckillRepository operatorSecckillRepository;
	
	@Autowired
	private  ProvideOrderFormRepository  provideOrderFormRepository;
	
	@Autowired
	private OperatorRefuseRecordRepository  operatorRefuseRecordRepository;
	
/**
 * 	
 * @param page
 * @param size
 * @param status   orderStatus;//订单状态 0 全部  订单状态1待支付  2待接单  3服务中  4待确认   5退款处理中(用户发起退款)   6已完成   7已关闭  8已关闭(退款完成)  9退款处理中(商家已拒绝退款)  10退款处理中(服务商接受退款并向财务发起退款,等待财务平台处理) 11已关闭(服务商发起关闭订单,等待财务平台退款) 12已关闭(未接单发生退款并且完成了退款)  13已完成（已评价）  14议价商品待沟通      15已关闭（已付款但未退款）
 * @param serverName
 * @param startOrderTime
 * @param endOrderTime
 * @param startOrderAmount
 * @param endOrderAmount
 * @param companyName
 * @param orderNum
 * @return
 */
	public    Map<String, Object>   queryOrderInfos(Integer  page,Integer size,String status,String serverName,String  startOrderTime,
            String endOrderTime,String startOrderAmount,String endOrderAmount,String companyName,String orderNum,String userid,String couponid,String busid){
		String jpql="select new guoanmaker.operator.business.modelnobind.OderFormRo(o.id,o.orderNumber,o.placeOrderTime,o.realPrice,o.orderStatus,o.invoiceState,"
				+ "u.name,c.commodityName,b.businessName,t.serverName,o.placeOrderType,o.preferentialMoney,u.username,b.companyName,o.couponid,o.truePrice,u.id as userid,o.commission,o.bail,o.fee,o.refundsAmount,o.returnPreferentialMoney)"
				+ "from ProvideOrderForm o left join o.user u left join o.commodity c left join c.providerBusiness b left join c.serviceType t   where 1=1";
		if (status != null && !status.equals("")) {
			if(status.equals("0")){
				
			} else	if (status.equals("14")) {
				jpql+="and (o.orderStatus='14')";
			}else if(status.equals("5")){
				jpql+="and (o.orderStatus='5' or o.orderStatus='9' or o.orderStatus='10')";
			}else if(status.equals("7")){
				jpql+="and (o.orderStatus='7' or o.orderStatus='8' or o.orderStatus='11' or o.orderStatus='12' or o.orderStatus='15')";
			}else if(status.equals("6")){
				jpql+="and (o.orderStatus='6' or o.orderStatus='13' )";
			}else{
				jpql += "and o.orderStatus='" + status + "' " ;
			}
		}
		if(serverName!=null&&!serverName.equals("")){
			jpql+="and t.serverName like '%"+serverName+"%'";
		} 
		
		if(startOrderTime!=null&&!startOrderTime.equals("")){
			
			String dates = startOrderTime; 
			dates = dates.replace("Z", " UTC");//注意是空格+UTC
			SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS Z");//注意格式化的表达式
			SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
			Date date=null;
			String str="";
			try {
				date = format.parse(dates);
				 str=sdf.format(date);  
			} catch (ParseException e) {
				e.printStackTrace();
			}
			jpql+="and o.placeOrderTime>='"+str+"'";
		}
		if(endOrderTime!=null&&!endOrderTime.equals("")){
			if(endOrderTime.equals(startOrderTime)){
				String datee = endOrderTime; 
				datee = datee.replace("Z", " UTC");//注意是空格+UTC
				SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS Z");//注意格式化的表达式
				SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
				Date date1=null;
				String str="";
				try {
					date1 = format.parse(datee);
					Date newDate = addDate(date1, 1); // 指定日期加上1天
					 str=sdf.format(newDate);  
				} catch (ParseException e) {
					e.printStackTrace();
				}
				jpql+="and o.placeOrderTime<'"+str+"'";
			}else{
				String datee = endOrderTime; 
				datee = datee.replace("Z", " UTC");//注意是空格+UTC
				SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS Z");//注意格式化的表达式
				SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
				Date date1=null;
				String str="";
				try {
					date1 = format.parse(datee);
					Date newDate = addDate(date1, 1); // 指定日期加上1天
					str=sdf.format(date1);  
				} catch (ParseException e) {
					e.printStackTrace();
				}
				jpql+="and o.placeOrderTime<='"+str+"'";
			}
		}

        if(startOrderAmount!=null&&!startOrderAmount.equals("")){
			jpql+="and o.truePrice >='"+startOrderAmount+"'";
		}
        if(endOrderAmount!=null&&!endOrderAmount.equals("")){
        	jpql+="and o.truePrice <='"+endOrderAmount+"'";
        }
		 if(companyName!=null&&!companyName.equals("")){
			jpql+="and b.businessName like '%"+companyName+"%'";
		}
		 if(orderNum!=null&&!orderNum.equals("")){
			jpql+="and o.orderNumber like '%"+orderNum+"%'";
		}
		 if(userid!=null&&!userid.equals("")){
			 jpql+="and u.id='" + userid + "' " ;
		 }
		 if(couponid!=null&&!couponid.equals("")){
			 jpql+="and o.couponid='" + couponid + "' " ;
		 }
		 if(busid!=null&&!busid.equals("")){
			 jpql+="and b.id='" + busid + "' " ;
			 
		 }
		 jpql+="order by o.placeOrderTime desc";
	    if(page==null){
				page=0;
			}
			if (size==null) {
				size=10;
			}
			Query query = em.createQuery(jpql);
			List<OderFormRo> result = query.getResultList();
			Map<String,Object>  map=new HashMap<>();
			map.put("totle", result.size());
			query.setFirstResult(page*size);
			query.setMaxResults(size);
			List<OderFormRo> result1 = query.getResultList();
			map.put("result", result1);
		return  map;
	}
	
	public static Date addDate(Date date,long day) throws ParseException {
		 long time = date.getTime(); // 得到指定日期的毫秒数
		 day = day*24*60*60*1000; // 要加上的天数转换成毫秒数
		 time+=day; // 相加得到新的毫秒数
		 return new Date(time); // 将毫秒数转换成日期
		}
	/**
	 * 秒杀活动列表
	 * @param page
	 * @param size
	 * @param status
	 * @param serverName
	 * @param startOrderTime
	 * @param endOrderTime
	 * @param startOrderAmount
	 * @param endOrderAmount
	 * @param companyName
	 * @param orderNum
	 * @param userid
	 * @param couponid
	 * @return
	 */
	
	public    Map<String, Object>   querymiaoOrderInfos(String id){
		List<OperatorSecckill> list=	operatorSecckillRepository.queryAllOperatorSecckillByActivityId(id);
		OperatorSecckill  operatorSecckill=null;
		 List<OderFormRo>  lists=new ArrayList<>();
		 Map<String,Object>  map=new HashMap<>();
		if(list.size()>0){
			for (int i = 0; i < list.size(); i++) {
				operatorSecckill= list.get(i);
				String comid=operatorSecckill.getCommodId();
				String jpql="select new guoanmaker.operator.business.modelnobind.OderFormRo(o.id,o.orderNumber,o.placeOrderTime,o.realPrice,o.orderStatus,o.defrayTime,o.invoiceState,"
						+ "u.name,c.commodityName,b.businessName,t.serverName,o.placeOrderType,o.preferentialMoney,u.username,b.companyName,o.couponid,o.truePrice,o.spikePrice)"
						+ "from ProvideOrderForm o left join o.user u left join o.commodity c left join c.providerBusiness b left join c.serviceType t   where 1=1";
				jpql+="and o.spikeid is not null and o.spikeid !='' and o.commodity='"+comid+"'";
				if(operatorSecckill.getSkStartTime()!=null&&!operatorSecckill.getSkStartTime().equals("")){
					String str="";
					SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
					str=sdf.format(operatorSecckill.getSkStartTime());  
					jpql+="and o.placeOrderTime>='"+str+"'";
				}
				if(operatorSecckill.getSkEndTime()!=null&&!operatorSecckill.getSkEndTime().equals("")){
					String str="";
					SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
					str=sdf.format(operatorSecckill.getSkEndTime());  
					jpql+="and o.placeOrderTime<='"+str+"'";
				}
				jpql+="order by o.placeOrderTime desc";
				Query query = em.createQuery(jpql);
				List<OderFormRo> result1 = query.getResultList();
				if(result1.size()>0){
					lists.addAll(result1);
				}
			}
		}
		map.put("result", lists);
		return  map;
	}
	
	/**
	 * 秒杀人数
	 * @param starttime
	 * @param endtime
	 * @return
	 */
	
	public    int   querycountnum(String id){
		int  a=0;
		List<OperatorSecckill> list=	operatorSecckillRepository.queryAllOperatorSecckillByActivityId(id);
		OperatorSecckill  operatorSecckill=null;
		 List<OderFormRo>  lists=new ArrayList<>();
		 Map<String,Object>  map=new HashMap<>();
		if(list.size()>0){
			for (int i = 0; i < list.size(); i++) {
				operatorSecckill=list.get(i);
				if(operatorSecckill.getSkStartTime()!=null&&operatorSecckill.getSkEndTime()!=null){
					int item=	provideOrderFormRepository.selectSpikenum(operatorSecckill.getCommodId(),operatorSecckill.getSkStartTime(), operatorSecckill.getSkEndTime());
					a+=item;
				}
				}
			}
		return a;
	}
	/**
	 *  秒杀全部订单
	 * @return
	 */
	public    List<OderFormRo>   exquerymiaoOrderInfos(String id){
		
		List<OperatorSecckill> list=	operatorSecckillRepository.queryAllOperatorSecckillByActivityId(id);
		OperatorSecckill  operatorSecckill=null;
		 List<OderFormRo>  lists=new ArrayList<>();
		 Map<String,Object>  map=new HashMap<>();
		if(list.size()>0){
			for (int i = 0; i < list.size(); i++) {
				operatorSecckill= list.get(i);
				String comid=operatorSecckill.getCommodId();
				String jpql="select new guoanmaker.operator.business.modelnobind.OderFormRo(o.id,o.orderNumber,o.placeOrderTime,o.realPrice,o.orderStatus,o.defrayTime,o.invoiceState,"
						+ "u.name,c.commodityName,b.businessName,t.serverName,o.placeOrderType,o.preferentialMoney,u.username,b.companyName,o.couponid,o.truePrice,o.spikePrice)"
						+ "from ProvideOrderForm o left join o.user u left join o.commodity c left join c.providerBusiness b left join c.serviceType t   where 1=1";
				jpql+="and o.spikeid is not null and o.spikeid !='' and o.commodity='"+comid+"'";
				if(operatorSecckill.getSkStartTime()!=null&&!operatorSecckill.getSkStartTime().equals("")){
					String str="";
					SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
					str=sdf.format(operatorSecckill.getSkStartTime());  
					jpql+="and o.placeOrderTime>='"+str+"'";
				}
				if(operatorSecckill.getSkEndTime()!=null&&!operatorSecckill.getSkEndTime().equals("")){
					String str="";
					SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
					str=sdf.format(operatorSecckill.getSkEndTime());  
					jpql+="and o.placeOrderTime<='"+str+"'";
				}
				jpql+="order by o.placeOrderTime desc";
				Query query = em.createQuery(jpql);
				List<OderFormRo> result1 = query.getResultList();
				lists.addAll(result1);
			}
		}
		return  lists;
	}
	public    List<OderFormRo>   exquerymiaoOrderInfoszhifu(String id){
		List<OperatorSecckill> list=	operatorSecckillRepository.queryAllOperatorSecckillByActivityId(id);
	    List<OderFormRo>  lists=new ArrayList<>();
	    OperatorSecckill  operatorSecckill=null;
		if(list.size()>0){
			for (int i = 0; i < list.size(); i++) {
				operatorSecckill= list.get(i);
				String comid=operatorSecckill.getCommodId();
				String jpql="select new guoanmaker.operator.business.modelnobind.OderFormRo(o.id,o.orderNumber,o.placeOrderTime,o.realPrice,o.orderStatus,o.defrayTime,o.invoiceState,"
						+ "u.name,c.commodityName,b.businessName,t.serverName,o.placeOrderType,o.preferentialMoney,u.username,b.companyName,o.couponid,o.truePrice,o.spikePrice)"
						+ "from ProvideOrderForm o left join o.user u left join o.commodity c left join c.providerBusiness b left join c.serviceType t   where 1=1";
				jpql+="and o.spikeid is not null and o.spikeid !='' and o.orderStatus != '1' and o.orderStatus != '7' and o.commodity='"+comid+"'";
				if(operatorSecckill.getSkStartTime()!=null&&!operatorSecckill.getSkStartTime().equals("")){
					String str="";
					SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
					str=sdf.format(operatorSecckill.getSkStartTime());  
					jpql+="and o.placeOrderTime>='"+str+"'";
				}
				if(operatorSecckill.getSkEndTime()!=null&&!operatorSecckill.getSkEndTime().equals("")){
					String str="";
					SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
					str=sdf.format(operatorSecckill.getSkEndTime());  
					jpql+="and o.placeOrderTime<='"+str+"'";
				}
				jpql+="order by o.placeOrderTime desc";
				Query query = em.createQuery(jpql);
				List<OderFormRo> result1 = query.getResultList();
				lists.addAll(result1);
			}
		}
		return  lists;
	}
	
	
	
	
	//带分页  订单查询
	public Map<String, Object> findByProperties(Integer page,Integer size,String status) {
		String jpql="select new guoanmaker.operator.business.modelnobind.OderFormRo(o.id,o.orderNumber,o.placeOrderTime,o.realPrice,o.orderStatus,o.invoiceState,"
				+ "u.name,c.commodityName,b.businessName,t.serverName)"
				+ "from ProvideOrderForm o left join o.user u left join o.commodity c left join c.providerBusiness b left join c.serviceType t   where 1=1";
		if (status != null && !status.equals("")) {
			if (!status.equals("0")) {
				jpql += "and o.orderStatus='" + status + "' " ;
			}
		}
		if(page==null){
			page=0;
		}
		if (size==null) {
			size=10;
		}
		Query query = em.createQuery(jpql);
		List<OderFormRo> result = query.getResultList();
		Map<String,Object>  map=new HashMap<>();
		map.put("totle", result.size());
		query.setFirstResult(page*size);
		query.setMaxResults(size);
		List<OderFormRo> result1 = query.getResultList();
		map.put("result", result1);
		return map;
	}
	//不带分页订单查询
	public   List<OderFormRo>   queryOrderInfosNoPage(String status){
		String jpql="select new guoanmaker.operator.business.modelnobind.OderFormRo(o.id,o.orderNumber,o.placeOrderTime,o.realPrice,o.orderStatus,o.invoiceState,"
				+ "u.name,c.commodityName,b.businessName,t.serverName)"
				+ "from ProvideOrderForm o left join o.user u left join o.commodity c left join c.providerBusiness b left join c.serviceType t   where 1=1";
		if (status != null && !status.equals("")) {
			if (!status.equals("0")) {
				jpql += "and o.orderStatus='" + status + "' " ;
			}
		}
		Query query1 = em.createQuery(jpql);
		List<OderFormRo> listI =query1.getResultList();
		return  listI;
	}
	public   List<OderFormRo>   queryOrderAllInfosNoPage(){
		String jpql="select new guoanmaker.operator.business.modelnobind.OderFormRo(o.id,o.orderNumber,o.placeOrderTime,o.realPrice,o.orderStatus,o.invoiceState,"
				+ "u.name,c.commodityName,b.businessName,t.serverName,o.placeOrderType,o.preferentialMoney,u.username,b.companyName,o.couponid,o.truePrice,u.id as userid,o.commission,o.bail,o.fee,o.refundsAmount)"
				+ "from ProvideOrderForm o left join o.user u left join o.commodity c left join c.providerBusiness b left join c.serviceType t   where 1=1";
	           jpql+=" order by o.placeOrderTime desc"; 
		Query query1 = em.createQuery(jpql);
		List<OderFormRo> listI =query1.getResultList();
		return  listI;
	}
	
	public ProvideOrderFormForOrder findByid(String id) {
		ProvideOrderFormForOrder order = new ProvideOrderFormForOrder();
		String jpql = "select new guoanmaker.operator.business.modelnobind.ProvideOrderFormForOrder"
				+ "(o.id,o.orderNumber,o.placeOrderTime,o.quantity,o.unitPrice,o.realPrice,o.truePrice,o.orderStatus,o.remark,o.defrayTime,"
				+ "o.acceptOrderTime,o.defrayNumber,o.applyforCompleteTime,o.confirmTime,o.applyforRefundsTime,"
				+ "o.confirmRefundsTime,o.denyRefundsTime,o.denyRefundsReason,o.contactPerson,o.contactNumber,"
				+ "o.requirementDescription,o.isOverChangePrice,o.orderType,o.userCompany,o.visitTime,o.visitorsNum,"
				+ "o.rentedBeginDate,o.rentedEndDate,o.rentedNum,o.commission,o.bail,o.fee,u.username,u.nickname,u.email,"
				+ "u.remark,c.commodityName,t.serverName,o.closeTime,c.invoiceMail,o.invoiceState,c.commodity_smallimage,o.placeOrderType,o.refundsAmount,o.preferentialMoney,o.paymentMethod,o.returnPreferentialMoney,b.businessName,b.LicensPhone)"
				+ "from ProvideOrderForm o left join o.user u left join o.commodity c left join c.providerBusiness b "
				+ "left join c.serviceType t where o.id='" + id + "'";
		Query query = em.createQuery(jpql);
		List<ProvideOrderFormForOrder> result = query.getResultList();
		if (result != null && result.size() > 0) {
			order = result.get(0);
			if(order.getOrderStatus().equals("6")||order.getOrderStatus().equals("13")){
				List<OperatorRefuseRecord>  list=	operatorRefuseRecordRepository.selectById(id);
				if(list.size()>0){
					order.setResonname(list.get(0).getReasonName());
				}
			}
		}
		return order;
	}
	
	
	public  List<Orderforbusiness>  selectByid(String  id){
		/*String jpql="select  o  from ProvideOrderForm o left  join o.user u  where u.id='"+ id + "'";*/
		  String   jpql = "select new guoanmaker.operator.business.modelnobind.Orderforbusiness(o.orderNumber,o.placeOrderTime, o.orderStatus,o.placeOrderType,b.businessName,t.serverName,u.name,u.nickname,o.realPrice)"
		     		+ " from ProvideOrderForm o left join o.user u left join o.commodity c left join c.providerBusiness b "
				+ "left join c.serviceType t where u.id='" + id + "'";
	    Query query = em.createQuery(jpql);
	    query.setFirstResult(0);
		query.setMaxResults(5);
		List<Orderforbusiness> result = query.getResultList();
		return result;
	}
	public  List<Orderforbusiness>  selectBycomid(String  id){
		 String   jpql = "select new guoanmaker.operator.business.modelnobind.Orderforbusiness(o.orderNumber,o.placeOrderTime, o.orderStatus,o.placeOrderType,b.businessName,t.serverName,u.name,u.nickname,o.realPrice)"
		     		+ " from ProvideOrderForm o left join o.user u left join o.commodity c left join c.providerBusiness b "
				+ "left join c.serviceType t where b.id='" + id + "'";
		Query query = em.createQuery(jpql);
		query.setFirstResult(0);
		query.setMaxResults(5);
		List<Orderforbusiness> result = query.getResultList();
		return result;
		
	}
	
	public  List<ProvideCommodity>  selectBycommid(String id){
		
		String  jpql="select com from ProvideCommodity com  left join  com.providerBusiness pb where  com.commodityState=2 and  pb.id='"+ id + "'";
		Query query = em.createQuery(jpql);
		query.setFirstResult(0);
		query.setMaxResults(5);
		List<ProvideCommodity> result = query.getResultList();
		return result;
	}
	
	public  List<Orderforbusiness>  selectByidbuy(String  id){
		  String   jpql = "select DISTINCT new guoanmaker.operator.business.modelnobind.Orderforbusiness(t.serverName)"
		     		+ " from ProvideOrderForm o left join o.user u left join o.commodity c left join c.providerBusiness b "
				+ "left join c.serviceType t where u.id='" + id + "'";
	    Query query = em.createQuery(jpql);
		List<Orderforbusiness> result = query.getResultList();
		return result;
	}
	public  List<Orderforbusiness>  selectByidbuycondition(String  id,String serverName){
		/*String jpql="select  o  from ProvideOrderForm o left  join o.user u  where u.id='"+ id + "'";*/
		  String   jpql = "select count(o.id)"
		     		+ " from ProvideOrderForm o left join o.user u left join o.commodity c left join c.providerBusiness b "
				+ "left join c.serviceType t where u.id='" + id + "' and t.serverName ='" + serverName + "'";
	    Query query = em.createQuery(jpql);
	    query.setFirstResult(0);
		query.setMaxResults(5);
		List<Orderforbusiness> result = query.getResultList();
		return result;
	}
	
	public List<BusinessServiceRange> selectByServer(String id){
		
		String jpql="select new guoanmaker.operator.business.modelnobind.BusinessServiceRange(r.old_commoditys,r.del_commoditys,r.ins_commoditys,"
			+"r.new_commoditys) from ProviderBusinessServerRange  r   left join r.business b where b.id='" + id + "'";
		 Query query = em.createQuery(jpql);
		 List<BusinessServiceRange> result = query.getResultList();
		return result;
	}
	/**
	 * 抽奖送
	 * @return
	 */
	public List<OperatorCoupons> usedConsponList(){
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date = new Date();
		String time=format.format(date);
		String jpql="select c from OperatorCoupons c where  "
				+ " c.startcouponstime<='"+time+"' and c.endcouponstime>='"+time+"' and c.iseffect=1 and c.delestatus!=1 and c.vouchtype='2'";
		Query query = em.createQuery(jpql);
		List<OperatorCoupons> result = query.getResultList();
		return result;
	}
	/**
	 *  累积签到送
	 * @return
	 */
	public List<OperatorCoupons> usedSigncumConsponList(){
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date = new Date();
		String time=format.format(date);
		String jpql="select c from OperatorCoupons c where  "
				+ " c.startcouponstime<='"+time+"' and c.endcouponstime>='"+time+"' and c.iseffect=1 and c.delestatus!=1 and c.vouchtype='3'";
		Query query = em.createQuery(jpql);
		List<OperatorCoupons> result = query.getResultList();
		return result;
	}
	/**
	 *  连续签到送
	 * @return
	 */
	public List<OperatorCoupons> usedSignConsponList(){
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date = new Date();
		String time=format.format(date);
		String jpql="select c from OperatorCoupons c where  "
				+ " c.startcouponstime<='"+time+"' and c.endcouponstime>='"+time+"' and c.iseffect=1 and c.delestatus!=1 and c.vouchtype='4'";
		Query query = em.createQuery(jpql);
		List<OperatorCoupons> result = query.getResultList();
		return result;
	}
	public List<OperatorCoupons> usedConsponNolimits(){
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date = new Date();
		String time=format.format(date);
		String jpql="select c from OperatorCoupons c where  "
				+ " c.startcouponstime<='"+time+"' and c.endcouponstime>='"+time+"' and c.iseffect=1 and c.delestatus!=1 and c.issuenumber=0";
		Query query = em.createQuery(jpql);
		List<OperatorCoupons> result = query.getResultList();
		return result;
	}
	
	
	
	
}
